import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:provide/provide.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/apis/video.dart';
import 'package:qgchat/http/models/listuserInfoModel.dart';
import 'package:qgchat/http/models/tokenuserInfoModel.dart';
import 'package:qgchat/states/states_model/user.dart';
import 'package:qgchat/widgets/tipsDialog.dart';
import 'package:qgchat/widgets/userInfoDialog.dart';

/// 根据对方的身份展示相应的用户信息
/// 对方是主播 跳转到主播详情页
/// 对方是用户 弹出用户信息弹窗
class ToUserInfo {
  /// 判断身份并作出选择
  static show(BuildContext context, String targetToken) async {
    final user = Provide.value<UserState>(context);
    final info = user.info;
    final isLogin = info != null;
    if (isLogin) {
      TokenuserInfoModel targetInfo =
          await VideoApis.tokenuserInfo(targetToken);
      switch (targetInfo.memberType) {
        case 1:
          showAnchor(context, targetToken);
          break;
        case 0:
          showUser(context, targetToken);
          break;
      }
    } else {
      TipsDialog.login(
        context,
        () {
          goPage(context, '/phoneLogin');
        },
      );
    }
  }

  /// 显示主播页
  static showAnchor(BuildContext context, String targetToken) {
    goPage(context, '/anchorInfo', param: {'token': targetToken});
  }

  /// 显示用户页
  static showUser(BuildContext context, String targetToken) async {
    if (targetToken == Config.CUSTOMERSERVICESTAFF) {
      return;
    }

    UserState userState = state(context, 'user');
    ListuserInfoModel targetInfo = await VideoApis.listuserInfo(
      userState.info.memberToken,
      targetToken,
    );
    showDialog(
      context: context,
      builder: (context) => UserInfoDialog(targetInfo: targetInfo),
    );
  }
}
